package org.springblade.modules.notice.core.event;

import org.springblade.common.utils.message.domain.SendRequest;
import org.springblade.modules.notice.core.callback.Callback;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public class CallbackEventListener implements ApplicationListener<CallbackEvent> {

    @Autowired
    private List<Callback> callbacks;

	@Async("callbackTaskExecutor")
    @Override
    public void onApplicationEvent(CallbackEvent event) {
        SendRequest sendRequest = event.getSendRequest();
        Map<String, Object> callbackData = event.getCallbackData();

        for (Callback callback : callbacks) {
            callback.execute(sendRequest, callbackData);
        }
    }
}
